home *** CD-ROM | disk | FTP | other *** search
/ Network Support Library / RoseWare - Network Support Library.iso / apidev / dax1.exe / DAP / DAPE / DAPIO.C < prev    next >
Text File  |  1992-07-15  |  4KB  |  116 lines

  1. //   ╔════════════════════════════════════════════════════════════════════╗
  2. //   ║                                                                    ║
  3. //   ║ module:      dapio.c                                               ║
  4. //   ║ abstract:    This module contains the screen IO logic.             ║
  5. //   ║                                                                    ║
  6. //   ║ environment: NetWare 3.x v3.11                                     ║
  7. //   ║              Network C for NLMs SDK                                ║
  8. //   ║              CLib v3.11                                            ║
  9. //   ║                                                                    ║
  10. //   ║  This software is provided as is and carries no warranty           ║
  11. //   ║  whatsoever.  Novell disclaims and excludes any and all implied    ║
  12. //   ║  warranties of merchantability, title and fitness for a particular ║
  13. //   ║  purpose.  Novell does not warrant that the software will satisfy  ║
  14. //   ║  your requirements or that the software is without defect or error ║
  15. //   ║  or that operation of the software will be uninterrupted.  You are ║
  16. //   ║  using the software at your risk.  The software is not a product   ║
  17. //   ║  of Novell, Inc. or any of subsidiaries.                           ║
  18. //   ║                                                                    ║
  19. //   ╟────────────────────────────────────────────────────────────────────╢
  20. //   ║ maintenance history:                                               ║
  21. //   ║ level    date      pi   description                                ║
  22. //   ╟────────────────────────────────────────────────────────────────────╢
  23. //   ║  001   02/24/92    kl   initial release.                           ║
  24. //   ╚════════════════════════════════════════════════════════════════════╝
  25.  
  26. #include    <stdio.h>
  27. #include    <stdarg.h>
  28. #include    <conio.h>
  29. #include    <process.h>
  30. #include    <nwsemaph.h>
  31.  
  32. #include    "dap/dapsys.h"
  33.  
  34. #define     MAXLINE     255
  35.  
  36. STATIC  LONG        ioSemaphore;
  37.  
  38. T_RC    DAPInitializeIOLogic()
  39. {
  40.         //
  41.         //  We need a local semaphore to block the print thread
  42.         //
  43.         if( (ioSemaphore = OpenLocalSemaphore(1)) == -1){
  44.             ioSemaphore = 0;    // so we don't accidentally close it
  45.             return DAP_RESOURCE_ERROR;
  46.         }
  47.         gotoxy(0,24);           // put cursor at bottom of screen
  48.         SetCtrlCharCheckMode(FALSE);
  49.         DIAG4("IO Logic has been initialized");
  50.         return DAP_SUCCESS;
  51. }
  52.  
  53. void    DAPDeInitializeIOLogic()
  54. {
  55.         //
  56.         //  Most of the time, this API will be called during atexit()
  57.         //  processing.
  58.         //
  59.         if( ioSemaphore ){
  60.             CloseLocalSemaphore(ioSemaphore);
  61.             ioSemaphore = 0;    // so it isn't closed again...
  62.         }
  63.         DIAG4("IO Logic has been DE-initialized");
  64. }
  65.  
  66. //
  67. //  Notice how both of the printing APIs make sure that a valid
  68. //  semaphore is available before calling the OS routine.  This is
  69. //  necessary since we may need to use these APIs while the IO
  70. //  engine has not been initialized.
  71. //
  72.  
  73. int     DAPatprintf(WORD row, WORD col, char *fmt, ... )
  74. {
  75.         int     rc;
  76.         char    _buf[MAXLINE];  // printf buffer
  77.         WORD    oldrow,oldcol;
  78.         va_list argp;           // pointer to arguments
  79.  
  80.         if( ioSemaphore ) WaitOnLocalSemaphore(ioSemaphore);
  81.         va_start(argp, fmt);
  82.         vsprintf(_buf, fmt, argp);
  83.         va_end(argp);
  84.         GetPositionOfOutputCursor( &oldrow, &oldcol );
  85.         gotoxy(col,row);
  86.         rc = printf(_buf);
  87.         gotoxy(oldcol,oldrow);
  88.         if( ioSemaphore ) SignalLocalSemaphore(ioSemaphore);
  89.         return rc;
  90. }
  91.  
  92. STATIC  LONG    cLine = 3; // current line number in bottom window
  93.  
  94. STATIC  void    DAPMoveCursorInStatusWindowDown( WORD lines )
  95. {
  96.         if( (cLine += lines) >= 23 ){
  97.             for( ; cLine > 22; --cLine )
  98.                 ScrollScreenRegionUp(4, 19);
  99.         }
  100. }
  101.  
  102. int     DAPprintf(char *fmt, ... )
  103. {
  104.         int     rc;
  105.         char    _buf[MAXLINE];  // printf buffer
  106.         va_list argp;           // pointer to arguments
  107.  
  108.         va_start(argp, fmt);
  109.         vsprintf(_buf, fmt, argp);
  110.         va_end(argp);
  111.         DAPMoveCursorInStatusWindowDown(1);
  112.         rc = DAPatprintf(cLine,0,_buf);
  113.         return rc;
  114. }
  115.  
  116.